package sg.com.techstudio.tafep.controller;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import sg.com.techstudio.tafep.dao.CompanyDao;
import sg.com.techstudio.tafep.dao.ConfigDao;
import sg.com.techstudio.tafep.obj.CompanyObj;
import sg.com.techstudio.tafep.obj.ConfigObj;

@Controller
public class RegisterController extends BaseController {
	private static final Log log = LogFactory.getLog(RegisterController.class);
	
	@Override
	protected String getModuleFolder() {
		return "register/";
	}
	
	@Autowired
	private CompanyDao companyDao;
	
	@Autowired
	private ConfigDao configDao;
	
	@RequestMapping(value="companyautocomplete"+SPRING_EXT)
	public String companyAutocomplete(Model model
			, @RequestParam(value = "query", required = false) String q) {
		log.debug("companyAutocomplete() entry");
		
		List<CompanyObj> companyList = companyDao.getCompanyList(q);
		model.addAttribute(PARAM_CONTENT_LIST, companyList);
		model.addAttribute("q", q);

		return goToPageJsp("companyText");
	}
	
	@RequestMapping(value="snefautocomplete"+SPRING_EXT)
	public String snefAutocomplete(Model model
			, @RequestParam(value = "query", required = false) String q) {
		log.debug("snefAutocomplete() entry");
		
		List<ConfigObj> snefList = configDao.getSnefList(q);
		model.addAttribute(PARAM_CONTENT_LIST, snefList);
		model.addAttribute("q", q);

		return goToPageJsp("snefText");
	}

}
